package vip.xiaozhao.paotui.controller.wallet;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaozhao.paotui.controller.BaseController;
import vip.xiaozhao.paotui.intf.dto.ResponseDO;
import vip.xiaozhao.paotui.intf.service.PaotuiWalletWithdrawService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;

@RestController
@RequestMapping("/wallet/withdraw")
@Slf4j
public class WalletController extends BaseController {

    @Autowired
    private PaotuiWalletWithdrawService walletWithdrawService;

    // 钱包提现流水和金额扣减, 事务注解（按理解最好不放在controller 层，放到service, 这里只做展示），
    @RequestMapping("/withdraw")
    public ResponseDO withdraw(BigDecimal withdrawAmount, HttpServletRequest request, HttpServletResponse response) {
        log.info("withdraw init, withdrawAmount:" + withdrawAmount);
        if (withdrawAmount == null){
            return ResponseDO.fail("提现金额不能为空");
        }
        int userId = getCurrentUserId(request);
        boolean result = walletWithdrawService.withdraw(withdrawAmount, userId);
        return ResponseDO.success(result);
    }


}
